package org.aplikator.server.descriptor;

import java.io.Serializable;

import org.aplikator.client.descriptor.LabelFieldDTO;
import org.aplikator.client.descriptor.WidgetDTO;
import org.aplikator.server.Context;

public class LabelField<T extends Serializable> implements Widget, HasProperty<T> {

    private Property<T> property;

    private boolean labelAbove = false;

    private String width;

    public LabelField(Property<T> property) {
        this.property = property;
    }

    public Property<T> getProperty() {
        return property;
    }

    public WidgetDTO getWidgetDescriptor(Context ctx) {
        LabelFieldDTO<T> desc = new LabelFieldDTO<T>(property.clientClone(ctx));
        desc.setLabelAbove(labelAbove);
        desc.setWidth(width);
        return desc;
    }

    public void registerProperties(Form form) {
        form.addProperty(property);
    }

    public boolean isLabelAbove() {
        return labelAbove;
    }

    public LabelField<T> setLabelAbove(boolean labelAbove) {
        this.labelAbove = labelAbove;
        return this;
    }

    public LabelField<T> setWidth(String width) {
        this.width = width;
        return this;
    }

    public String getWidth() {
        return width;
    }
}
